JavaScript Arithmetic Operators

Visualizing `**`, `*`, `/`, `%`, `+`, and `-`.

`**`, `*`, `/`, `%`

These operators perform standard mathematical operations. **`**`** performs exponentiation, **`*`** is multiplication, **`/`** is division, and **`%`** returns the remainder of a division.

5 ** 2; // 25
10 * 3; // 30
10 / 3; // 3.333...
10 % 3; // 1

Exponentiation (`**`)

Expression: `2 ** 3`

Result:

Multiplication (`*`)

Expression: `5 * 4`

Result:

Division (`/`)

Expression: `10 / 4`

Result:

Remainder (`%`)

Expression: `10 % 3`

Result:


`+` and `-`

The **addition (`+`)** and **subtraction (`-`)** operators perform basic arithmetic. However, the addition operator also handles string concatenation. This is a common source of confusion if operands are of mixed types.

10 + 5;      // 15
"10" + "5";  // "105"
"10" + 5;    // "105"
10 - 5;      // 5

Addition (`+`)

Expression: `5 + 10`

Result:

Expression: `"5" + "10"`

Result:

Expression: `"5" + 10`

Result:

Subtraction (`-`)

Expression: `10 - 5`

Result:

Expression: `"10" - "5"`

Result:

Expression: `"10" - 5`

Result: